/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.wtw.konnekt;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Adam
 */
public class Chat {
    public static String CONTACT_NET_GG = "GG";
    public static String CONTACT_NET_XMPP = "XMPP";
    private long indexId;
    private String contactId;
    private String contactNet;
    private String contactName;
//    private String contactUuid;
    private long startTime;
//    private int flags;
    private List<Message> messages = new ArrayList<Message>();

    public Chat(long indexId, String contactId, String contactNet, long startTime) {
        this.indexId = indexId;
        this.contactId = contactId;
        this.contactNet = contactNet;
        this.startTime = startTime;
    }

    public Chat(String contactName, String sStartDate, String sStartTime) throws ParseException {
        DateFormat df = new SimpleDateFormat("dd-MM-yyyy kk:mm:ss");
        Date date;
        try {
            if (sStartDate!=null && sStartTime!=null) {
                date = df.parse(sStartDate+" "+sStartTime);
            } else {
               return;
            }
        } catch (ParseException ex) {
            df = new SimpleDateFormat("dd-MM-yyyy kk:mm");
            date = df.parse(sStartDate+" "+sStartTime);
        }

        this.startTime = date.getTime()/1000;
        this.contactName = contactName;
    }

    public void addMessage(Message msg) {
        if (contactNet==null) {
            contactNet = msg.getContactNet();
        }
        if (contactId==null||contactId.length()==0) {
            contactId = msg.getContactId();
        }
        messages.add(msg);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Chat\n");
        sb.append("ContactId: "+contactId);
        sb.append("\n");
        sb.append("ContactNet: "+contactNet);
        sb.append("\n");
        sb.append("StartTime: "+DateFormat.getInstance().format(new Date(startTime*1000)));
        sb.append("\n");
        sb.append("Messages: "+messages);
        return sb.toString();
    }

    /**
     * @return the indexId
     */
    public long getIndexId() {
        return indexId;
    }

    /**
     * @param indexId the indexId to set
     */
    public void setIndexId(long indexId) {
        this.indexId = indexId;
    }

    /**
     * @return the contactId
     */
    public String getContactId() {
        return contactId;
    }

    /**
     * @param contactId the contactId to set
     */
    public void setContactId(String contactId) {
        this.contactId = contactId;
    }

    /**
     * @return the contactNet
     */
    public String getContactNet() {
        return contactNet;
    }

    /**
     * @param contactNet the contactNet to set
     */
    public void setContactNet(String contactNet) {
        this.contactNet = contactNet;
    }

    /**
     * @return the contactName
     */
    public String getContactName() {
        return contactName;
    }

    /**
     * @param contactName the contactName to set
     */
    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    /**
     * @return the startTime
     */
    public long getStartTime() {
        return startTime;
    }

    /**
     * @param startTime the startTime to set
     */
    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    /**
     * @return the messages
     */
    public List<Message> getMessages() {
        return messages;
    }

    /**
     * @param messages the messages to set
     */
    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }

 



    


}
